const mongoose = require('./db')
const userSchema = new mongoose.Schema({
  username: String,
  password: String,
  phone: String,
  avatar: String,
  signedDates: [{
    monthYear: String,
    date: String
  }]
})
const userModel = mongoose.model('user8888', userSchema)


let goods = new mongoose.Schema({
  name: String,
  price: Number,
  img: Array,
  type: String,
  num: Number,
  color: Array,
  size: Array,
  city: String,
  sty: String,
  sc: Array,
  runprice: Number,
  title: String,
  fshop: String,
  sextype: String,
  s_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'shop'
  }
})

let goodcar = new mongoose.Schema({
  uid: String,
  name: String,
  price: Number,
  img: String,
  gid: {
    type: mongoose.Types.ObjectId,
    ref: 'goods'
  },
  num: Number,
  color: String,
  size: String,
  having: String,
  pname: String
})


let addressSchema = new mongoose.Schema({
  name: String,
  phone: String,
  city: String,
  isDefault: {
    type: Boolean,
    default: false,
  },
  u_id: {
    type: mongoose.Types.ObjectId,
    ref: "user8888",
  }
})
let roomSchema = new mongoose.Schema({
  roomname: String,
  users: [String],
  messages: [
    {
      sender: String,
      content: String,
      timestamp: { type: Date, default: Date.now },
    },
  ],
})

let gn=new mongoose.Schema({
  text: String,
  img:Array
})

// let shopTypeModel = mongoose.model("shopType", ShopTypeSchema, "shopType");
// let goodcarmodel = mongoose.model('goodcar', goodcar, 'goodcar')
// let shopmodel = mongoose.model('shop', shop, 'shop')
// let gomodel = mongoose.model('goods', goods, 'goods')
// let roomModel = mongoose.model("room", roomSchema, "room")
// let address = mongoose.model('address', addressSchema, 'address')
// module.exports = { gomodel, shopmodel, userModel, shopTypeModel, address, goodcarmodel, roomModel}

// })
let shop = new mongoose.Schema({
  name: String,
  type: Array,
  img: String,
  hot: Number
})

let ShopTypeSchema = new mongoose.Schema({
  name: String,
  img: String,
  level: Number,

  pid: {
    type: [mongoose.Schema.Types.ObjectId],
    ref: "shopType",
  },
});

let couponSchema = new mongoose.Schema({
  title: String,
  price: Number,
  num: {
    type: Number,
    default: 0
  },
  status: {
    type: Boolean,
    default: false,
  },
  startTime: {
    type: Date,
    default: Date.now(),
  },
  endTime: {
    type: Date,
    default: Date.now() + 30 * 24 * 60 * 60 * 1000,
  },
  cid: {
    type: mongoose.Types.ObjectId,
    ref: "UserCoupon",
  }
});
const userCouponSchema = new mongoose.Schema({
  userId: String,


  couponId: {
    type: mongoose.Types.ObjectId,
    ref: "coupon",
  },
  status: {
    type: Boolean,
    default: false
  }
});



const commentSchema = new mongoose.Schema({
  userId: {
    type: mongoose.Types.ObjectId,
    ref: "user8888",
    default: new mongoose.Types.ObjectId("670637e24b51aa7b2e437c1e"),
  },
  shopId: {
    type: mongoose.Types.ObjectId,
    ref: "shop",
    default: new mongoose.Types.ObjectId("66eac6780dc3532ceaa24d02"),
  },
  goodsId: {
    type: mongoose.Types.ObjectId,
    ref: "goods",
    default: new mongoose.Types.ObjectId("66eac6780dc3532ceaa24d02"),
  },
  shopRate: {
    type: Number,
    default: 0,
  },
  goodsRate: {
    type: Number,
    default: 0,
  },
  serviceRate: {
    type: Number,
    default: 0,
  },

  comment: String,
  img: {
    type: Array,
    default: [],
  },
  time: {
    type: Date,
    default: Date.now(),
  },
  //浏览次数
  browseNum: {
    type: Number,
    default: 0,
  },

  //点赞次数
  praiseNum: {
    type: Number,
    default: 0,
  },
  level: {
    type: Number,
    default: 1,
  },
  pid: {
    type: mongoose.Types.ObjectId,
    ref: "comment",
  },
});
//评论
const commentModel = mongoose.model("comment", commentSchema, "comment");



//用户优惠券
const UserCoupon = mongoose.model("UserCoupon", userCouponSchema, "UserCoupon");

// 优惠券
let couponModel = mongoose.model("coupon", couponSchema, "coupon");

//分类
let shopTypeModel = mongoose.model("shopType", ShopTypeSchema, "shopType");


// 商铺
let shopmodel = mongoose.model('shop', shop, 'shop')


//商品




let gomodel = mongoose.model('goods', goods, 'goods')

// let addressSchema = new mongoose.Schema({
//     name: String,
//     phone: String,
//     city: String,
//     isDefault: {
//         type: Boolean,
//         default: false,
//     },
//     u_id: {
//         type: mongoose.Types.ObjectId,
//         ref: "user8888",
//     }
// })
// let goodcar = new mongoose.Schema({
//     uid: String,
//     name: String,
//     price: Number,
//     img: String,
//     gid: {
//         type: mongoose.Types.ObjectId,
//         ref: 'goods'
//     },
//     num: Number,
//     color: String,
//     size: String,
//     having: String
// })












let address = mongoose.model('address', addressSchema, 'address')
let goodcarmodel = mongoose.model('goodcar', goodcar, 'goodcar')
let roomModel = mongoose.model("room", roomSchema, "room")
let gnmodel = mongoose.model("gn", gn, "gn")
module.exports = { gomodel, shopmodel, userModel, shopTypeModel, goodcarmodel,address,roomModel,couponModel,UserCoupon,commentModel,gnmodel }

